<template>
	<view class="numberSelector">
		<view class="mybtn" @click="setNum(1)"> <text class="txt">-</text> </view>
		<input class="myinput" type="number" v-model="num" disabled/>
		<view class="mybtn" @click="setNum(2)"> <text class="txt">+</text> </view>
	</view>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import { useStore } from 'vuex'
	export default defineComponent({
		components:{
			
		},
		props:{
			modelValue:Number,
		},

		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				num:props.modelValue || ''
			})
			state.num = props.modelValue
			
			onMounted(()=>{
				
			})
			
			const setNum = (flag)=>{
				if(flag==1){
					if(state.num>=1){
						state.num--
					}
				}else if(flag==2){
					state.num++
				}
				context.emit('update:modelValue',state.num)
				context.emit('onchange',state.num)
			}
			
			return {
				...toRefs(state),
				setNum
			}
		}
	})
</script>

<style lang="scss" scoped>
	.numberSelector{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		.mybtn{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 80rpx;
			height: 80rpx;
			// border: 1px solid #fba70e;
			.txt{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 50rpx;
				height: 50rpx;
				border: 1px solid #fba70e;
				font-size: 40rpx;
				border-radius: 10rpx;
				color: #333;
			}
		}
		.myinput{
			flex: 1;
			text-align: center;
		}
	}
</style>
